/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 9/30/12
 * Time: 12:43 AM
 * To change this template use File | Settings | File Templates.
 */
package vplib.toolbox {
import flash.utils.Dictionary;

import mx.collections.ArrayCollection;

import vplib.component.AbstractPhysicsComponent;
import vplib.component.IPhysicsComponent;

import vplib.component.MaterialPointComponent;
import vplib.component.body.BodyBoxComponent;
import vplib.component.body.BodySphereComponent;

public class AvailableComponentsDictionary {
    private static var listNames:ArrayCollection = null;
    private static var components:ArrayCollection = null;

    public function AvailableComponentsDictionary() {
        //
    }

    private static function init():void {
        listNames = new ArrayCollection();
        components = new ArrayCollection();

        listNames.addItem({label:new MaterialPointComponent("").getComponentName()});
        components.addItem(new MaterialPointComponent(""));

        listNames.addItem({label:new BodyBoxComponent("").getComponentName()});
        components.addItem(new BodyBoxComponent(""));

        listNames.addItem({label:new BodySphereComponent("").getComponentName()});
        components.addItem(new BodySphereComponent(""));
    }

    public static function getList():ArrayCollection {
        if (components == null || listNames == null)
            init();

        return listNames;
    }

    public static function getComponentInstanceByName(name:String):IPhysicsComponent {
        if (components == null || listNames == null)
            init();

        for each (var comp:IPhysicsComponent in components) {
            if (comp.getComponentName() == name) {
                return comp.createNewInstance();
            }
        }
        return null;
    }
}
}
